<template>
  <div class="error-page server-error-page">
    <!-- 电子脑波背景 -->
    <div class="ai-brainwave-background">
      <div class="wave wave-1"></div>
      <div class="wave wave-2"></div>
      <div class="wave wave-3"></div>
      <div class="datapoint dp-1"></div>
      <div class="datapoint dp-2"></div>
      <div class="datapoint dp-3"></div>
      <div class="datapoint dp-4"></div>
      <div class="datapoint dp-5"></div>
      <div class="datapoint dp-6"></div>
    </div>
    
    <div class="content-container">
      <!-- AI服务器图像 -->
      <div class="error-visual">
        <div class="server-container">
          <div class="server-rack">
            <div class="server-light blink-light"></div>
            <div class="server-light error-light"></div>
            <div class="server-panel"></div>
            <div class="server-vent"></div>
            <div class="server-vent"></div>
          </div>
          <div class="ai-core">
            <div class="core-ring"></div>
            <div class="core-ring"></div>
            <div class="core-ring"></div>
            <div class="core-center">
              <span class="error-code">500</span>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 错误信息 -->
      <h1 class="error-title">神经网络异常</h1>
      <p class="error-description">
        我们的AI服务器遇到了意外的认知障碍。技术团队已经收到脑波异常警报，正在进行治疗。
        <span class="system-status">系统状态: <span class="status-text">自我修复中</span></span>
      </p>
      
      <!-- 诊断信息 -->
      <div class="ai-diagnostics">
        <div class="diagnostics-header">
          <i class="fas fa-microchip"></i>
          <span>AI系统诊断</span>
        </div>
        <div class="diagnostics-content">
          <div class="diagnostics-progress">
            <div class="progress-bar">
              <div class="progress-fill"></div>
            </div>
            <div class="progress-text">正在诊断... <span class="progress-percentage">68%</span></div>
          </div>
          <div class="diagnostics-log">
            <div class="log-entry">
              <span class="timestamp">12:42:03</span>
              <span class="log-text">检测到神经递质异常，启动自动恢复程序</span>
            </div>
            <div class="log-entry">
              <span class="timestamp">12:42:15</span>
              <span class="log-text">重建中... 认知框架升级中</span>
            </div>
            <div class="log-entry">
              <span class="timestamp">12:42:38</span>
              <span class="log-text">预计恢复时间: 3分钟</span>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 操作选项 -->
      <div class="action-options">
        <div class="action-card" @click="reloadPage">
          <i class="fas fa-sync-alt"></i>
          <span>刷新页面</span>
          <small>重启数据流</small>
        </div>
        <div class="action-card" @click="reportError">
          <i class="fas fa-bug"></i>
          <span>报告故障</span>
          <small>帮助AI学习</small>
        </div>
        <router-link to="/" class="action-card">
          <i class="fas fa-home"></i>
          <span>返回首页</span>
          <small>安全区域</small>
        </router-link>
      </div>
    </div>
    
    <!-- 技术支持悬浮窗 -->
    <div class="tech-support-widget" :class="{ 'open': showSupport }">
      <div class="widget-header" @click="toggleSupport">
        <i class="fas fa-headset"></i>
        <span>技术支持</span>
        <i class="fas" :class="showSupport ? 'fa-chevron-down' : 'fa-chevron-up'"></i>
      </div>
      <div class="widget-content" v-if="showSupport">
        <p>我们的技术人员正在处理此问题。如需立即联系支持人员：</p>
        <div class="contact-method">
          <i class="fas fa-envelope"></i>
          <span>support@aidizhikao.com</span>
        </div>
        <div class="contact-method">
          <i class="fas fa-phone"></i>
          <span>400-800-8888</span>
        </div>
        <div class="tech-action">
          <button class="btn-tech-help" @click="requestHelp">
            <i class="fas fa-robot"></i> 请求AI助手
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ServerError',
  data() {
    return {
      showSupport: false,
      progressValue: 0,
      progressInterval: null
    }
  },
  methods: {
    toggleSupport() {
      this.showSupport = !this.showSupport;
    },
    reloadPage() {
      window.location.reload();
    },
    reportError() {
      // 报告错误的逻辑
      alert('感谢您的反馈！系统已记录此错误，我们的技术人员会尽快处理。');
    },
    requestHelp() {
      alert('AI助手正在连接，请稍候...');
    },
    animateProgressBar() {
      this.progressInterval = setInterval(() => {
        if (this.progressValue < 68) {
          this.progressValue += Math.random() * 5;
          if (this.progressValue > 68) this.progressValue = 68;
          
          const progressFill = document.querySelector('.progress-fill');
          if (progressFill) {
            progressFill.style.width = `${this.progressValue}%`;
          }
        } else {
          clearInterval(this.progressInterval);
        }
      }, 300);
    }
  },
  mounted() {
    // 启动进度条动画
    this.animateProgressBar();
    
    // 启动数据点动画
    document.querySelectorAll('.datapoint').forEach((dot, index) => {
      setTimeout(() => {
        dot.classList.add('pulse');
      }, index * 400);
    });
    
    // 波浪动画
    document.querySelectorAll('.wave').forEach((wave, index) => {
      wave.style.animationDelay = `${index * 0.5}s`;
    });
  },
  beforeDestroy() {
    if (this.progressInterval) {
      clearInterval(this.progressInterval);
    }
  }
}
</script>

<style lang="less" scoped>
@import "@/styles/variables.less";

.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background-color: #f0f4fd;
  position: relative;
  padding: 2rem;
  overflow: hidden;
  font-family: 'Segoe UI', 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
}

// 脑波背景
.ai-brainwave-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  overflow: hidden;
  
  .wave {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, transparent, @primary-light, transparent);
    width: 100%;
    opacity: 0.3;
    animation: wave 8s infinite;
    
    &.wave-1 {
      top: 20%;
    }
    
    &.wave-2 {
      top: 50%;
    }
    
    &.wave-3 {
      top: 80%;
    }
  }
  
  .datapoint {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: fade(@primary, 20%);
    transform: scale(0);
    
    &.pulse {
      animation: pulse 4s infinite;
    }
    
    &.dp-1 { top: 20%; left: 20%; }
    &.dp-2 { top: 30%; left: 70%; }
    &.dp-3 { top: 50%; left: 30%; }
    &.dp-4 { top: 60%; left: 80%; }
    &.dp-5 { top: 70%; left: 40%; }
    &.dp-6 { top: 80%; left: 60%; }
  }
}

@keyframes wave {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

@keyframes pulse {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(0); opacity: 0; }
}

.content-container {
  max-width: 800px;
  width: 100%;
  z-index: 1;
  background: rgba(255, 255, 255, 0.8);
  padding: 3rem;
  border-radius: 20px;
  box-shadow: @shadow-lg;
  backdrop-filter: blur(10px);
  animation: fadeIn 0.8s ease;
  text-align: center;
}

// 服务器可视化
.error-visual {
  margin-bottom: 2rem;
  position: relative;
  height: 180px;
  
  .server-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    
    .server-rack {
      width: 160px;
      height: 140px;
      background: linear-gradient(135deg, #2a2a3a, #1a1a2a);
      border-radius: 8px;
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      box-shadow: 0 10px 20px rgba(0,0,0,0.2);
      z-index: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 10px;
      
      .server-light {
        position: absolute;
        width: 10px;
        height: 10px;
        border-radius: 50%;
        top: 15px;
        
        &.blink-light {
          left: 15px;
          background-color: @success;
          animation: blink 1.5s infinite;
        }
        
        &.error-light {
          left: 35px;
          background-color: @error;
          animation: blink 0.5s infinite;
        }
      }
      
      .server-panel {
        width: 100%;
        height: 20px;
        background: rgba(255,255,255,0.05);
        border-radius: 4px;
        margin-top: 25px;
      }
      
      .server-vent {
        width: 100%;
        height: 8px;
        background: repeating-linear-gradient(
          90deg,
          rgba(255,255,255,0.05),
          rgba(255,255,255,0.05) 5px,
          transparent 5px,
          transparent 10px
        );
        margin-top: 10px;
      }
    }
    
    .ai-core {
      position: absolute;
      width: 120px;
      height: 120px;
      z-index: 2;
      display: flex;
      align-items: center;
      justify-content: center;
      
      .core-ring {
        position: absolute;
        border: 2px solid fade(@primary, 60%);
        border-radius: 50%;
        animation: ring-pulse 3s infinite;
        
        &:nth-child(1) {
          width: 100%;
          height: 100%;
          animation-delay: 0s;
        }
        
        &:nth-child(2) {
          width: 80%;
          height: 80%;
          animation-delay: 0.5s;
        }
        
        &:nth-child(3) {
          width: 60%;
          height: 60%;
          animation-delay: 1s;
        }
      }
      
      .core-center {
        width: 50%;
        height: 50%;
        background: linear-gradient(135deg, @primary, @secondary);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 0 20px fade(@primary, 50%);
        animation: glow 2s infinite alternate;
        
        .error-code {
          color: white;
          font-size: 1.2rem;
          font-weight: 700;
        }
      }
    }
  }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes ring-pulse {
  0% { transform: scale(0.8); opacity: 0.8; }
  50% { transform: scale(1.1); opacity: 0.4; }
  100% { transform: scale(0.8); opacity: 0.8; }
}

@keyframes glow {
  0% { box-shadow: 0 0 10px fade(@primary, 50%); }
  100% { box-shadow: 0 0 25px fade(@primary, 70%); }
}

.error-title {
  font-size: 2.2rem;
  color: @gray-800;
  margin-bottom: 1rem;
  font-weight: 700;
}

.error-description {
  font-size: 1.1rem;
  color: @gray-700;
  margin-bottom: 2rem;
  
  .system-status {
    display: block;
    margin-top: 1rem;
    font-weight: 500;
    
    .status-text {
      color: @primary;
      background: fade(@primary-light, 30%);
      padding: 0.2rem 0.5rem;
      border-radius: @radius-md;
      animation: pulse-text 2s infinite;
    }
  }
}

@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

// AI诊断模块
.ai-diagnostics {
  background: white;
  border-radius: @radius-lg;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: @shadow-md;
  text-align: left;
  
  .diagnostics-header {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid @gray-200;
    
    i {
      color: @primary;
      margin-right: 0.75rem;
      font-size: 1.2rem;
    }
    
    span {
      font-weight: 600;
      color: @gray-800;
    }
  }
  
  .diagnostics-content {
    .diagnostics-progress {
      margin-bottom: 1rem;
      
      .progress-bar {
        height: 8px;
        background-color: @gray-200;
        border-radius: 4px;
        overflow: hidden;
        margin-bottom: 0.5rem;
        
        .progress-fill {
          height: 100%;
          background: linear-gradient(90deg, @primary, @secondary);
          width: 0%;
          transition: width 0.3s ease;
        }
      }
      
      .progress-text {
        font-size: 0.875rem;
        color: @gray-600;
        display: flex;
        justify-content: space-between;
        
        .progress-percentage {
          font-weight: 600;
          color: @primary;
        }
      }
    }
    
    .diagnostics-log {
      background-color: @gray-50;
      border-radius: @radius-md;
      padding: 1rem;
      height: 120px;
      overflow-y: auto;
      font-family: 'Courier New', monospace;
      font-size: 0.875rem;
      
      .log-entry {
        margin-bottom: 0.75rem;
        color: @gray-700;
        
        .timestamp {
          color: @secondary;
          margin-right: 0.5rem;
        }
      }
    }
  }
}

// 操作选项卡片
.action-options {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 1rem;
  
  .action-card {
    background-color: white;
    border-radius: @radius-md;
    padding: 1.5rem 1rem;
    min-width: 140px;
    text-align: center;
    box-shadow: @shadow-sm;
    transition: all 0.3s ease;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid @gray-200;
    
    i {
      font-size: 1.5rem;
      color: @primary;
      margin-bottom: 0.5rem;
      display: block;
    }
    
    span {
      display: block;
      color: @gray-800;
      font-weight: 500;
      margin-bottom: 0.25rem;
    }
    
    small {
      color: @gray-500;
      font-size: 0.75rem;
    }
    
    &:hover {
      transform: translateY(-5px);
      box-shadow: @shadow-md;
      border-color: @primary-light;
    }
  }
}

// 技术支持悬浮窗
.tech-support-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 300px;
  background-color: white;
  border-radius: @radius-md;
  box-shadow: @shadow-xl;
  z-index: 10;
  overflow: hidden;
  transition: all 0.3s ease;
  
  .widget-header {
    padding: 1rem;
    background: linear-gradient(90deg, @primary, @secondary);
    color: white;
    display: flex;
    align-items: center;
    cursor: pointer;
    
    i:first-child {
      margin-right: 0.5rem;
    }
    
    span {
      flex: 1;
      font-weight: 500;
    }
  }
  
  .widget-content {
    padding: 1.25rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    
    p {
      margin-bottom: 1rem;
      color: @gray-700;
      font-size: 0.875rem;
    }
    
    .contact-method {
      display: flex;
      align-items: center;
      margin-bottom: 0.75rem;
      
      i {
        color: @primary;
        margin-right: 0.75rem;
        width: 16px;
      }
      
      span {
        color: @gray-800;
        font-size: 0.875rem;
      }
    }
    
    .tech-action {
      margin-top: 1rem;
      
      .btn-tech-help {
        width: 100%;
        padding: 0.75rem;
        background-color: @primary;
        color: white;
        border: none;
        border-radius: @radius-md;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 0.5rem;
        
        &:hover {
          background-color: darken(@primary, 10%);
        }
      }
    }
  }
  
  &.open {
    .widget-content {
      max-height: 400px;
    }
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

// 响应式调整
@media (max-width: 768px) {
  .content-container {
    padding: 2rem 1.5rem;
  }
  
  .error-title {
    font-size: 1.8rem;
  }
  
  .action-options {
    flex-direction: column;
    
    .action-card {
      width: 100%;
    }
  }
  
  .tech-support-widget {
    width: calc(100% - 2rem);
    right: 1rem;
    bottom: 1rem;
  }
  
  .error-visual {
    transform: scale(0.8);
  }
}
</style> 